#include <iostream>
#include <queue>

using namespace std;


/**
 * 合并果子
 * 测试链接：https://www.luogu.com.cn/problem/P1090
 */
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	priority_queue<int, vector<int>, greater<>> q;

	int n;
	cin >> n;

	for(int i=0; i<n; i++) {
		int x;
		cin >> x;
		q.push(x);
	}


	int result = 0;
	while(q.size() > 1) {
		int first = q.top();
		q.pop();
		
		int second = q.top();
		q.pop();	
		

		int sum = first + second;
		q.push(sum);

		result += sum;
	}

	cout << result;

	return 0;
}